import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import employeesRoute from "@/router/modules/employees";
import approvalsRoute from "@/router/modules/approvals";
import attendancesRoute from "@/router/modules/attendances";
import settingsRoute from "@/router/modules/settings";
import departmentsRoute from "@/router/modules/departments";
import permissionsRoute from "@/router/modules/permissions";
import salarysRoute from "@/router/modules/salarys";
import socialSecuritysRoute from "@/router/modules/social_securitys";

// 动态路由配置
export const asyncRoutes = [
    departmentsRoute,
    settingsRoute,
    employeesRoute,
    permissionsRoute,
    approvalsRoute,
    attendancesRoute,
    salarysRoute,
    socialSecuritysRoute
]



// 静态路由配置
export const constantRoutes = [
  {
    path:'/demo',
    name:'demo',
    component:()=> import('@/views/demo/index.vue')
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/upload',
    component: () => import('@/views/excel/upload'),
    name: 'UploadExcel',
    meta: { title: 'Upload Excel' }
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes,...asyncRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
